package com.sinosoft.cnmuseum.servlets;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.sinosoft.cnmuseum.dao.MbGyByflDao;
import com.sinosoft.cnmuseum.dao.MbGyHsflDao;
import com.sinosoft.cnmuseum.dao.MbGyMjflDao;
import com.sinosoft.cnmuseum.dao.MbGyNdDao;
import com.sinosoft.cnmuseum.dao.MbGyYqflDao;
import com.sinosoft.cnmuseum.dao.MbGyYyDao;
import com.sinosoft.cnmuseum.dao.MbGyZqDao;
import com.sinosoft.cnmuseum.dao.MbManageAudiofrequencyDao;
import com.sinosoft.cnmuseum.dao.MbManageImageDao;
import com.sinosoft.cnmuseum.dao.MbManageLiteratureDao;
import com.sinosoft.cnmuseum.dao.MbManageThreedimensionalmodelDao;
import com.sinosoft.cnmuseum.dao.MbManageVideoDao;
import com.sinosoft.cnmuseum.dao.MbMusicGcxxDao;
import com.sinosoft.cnmuseum.dao.MbSjjsInfoDao;
import com.sinosoft.cnmuseum.dao.MbsjjsDao;
import com.sinosoft.cnmuseum.entity.MbGyHsfl;
import com.sinosoft.cnmuseum.entity.MbGyMjfl;
import com.sinosoft.cnmuseum.entity.MbManageAudiofrequency;
import com.sinosoft.cnmuseum.entity.MbManageImage;
import com.sinosoft.cnmuseum.entity.MbManageLiterature;
import com.sinosoft.cnmuseum.entity.MbManageThreedimensionalmodel;
import com.sinosoft.cnmuseum.entity.MbManageVideo;
import com.sinosoft.cnmuseum.entity.MbMusicGcxx;
import com.sinosoft.cnmuseum.entity.MbMusicWhrlxxx;
import com.sinosoft.cnmuseum.entity.MbMusicXzxx;
import com.sinosoft.cnmuseum.entity.MbMusicYxxx;
import com.sinosoft.cnmuseum.utils.PageUtil;
import com.sinosoft.cnmuseum.utils.Status;
import com.sinosoft.cnmuseum.utils.StringUtils;
import com.sinosoft.commontools.annotated.TransAnnotation;
import com.sinosoft.commontools.annotated.rquestMethod;
import com.sinosoft.commontools.annotated.rquestMethod.ReqMode;
import com.sinosoft.commontools.record.Record;

public class MbGcxxServlet {
	
	private static Logger logger = Logger.getLogger(MbGcxxServlet.class);
//	@rquestMethod(MethodNote = ReqMode.All)
//	public Record getData(HttpServletRequest request, HttpServletResponse response, Record data){
//		Record record = new Record();
//		record.add(Status.SATUS, Status.OK);
//		try {
//			int pagenumber = data.getIntValue(Status.PAGENUMBER);// 获取当前页
//			int pagesize = data.getIntValue(Status.PAGESIZE);// 获取每页多少条数据
//			// 数据   最新数据
//			String countsql = "select count(*) as count from mb_music_gcxx where isnew=1  ";
//			String sql = "select * from mb_music_gcxx where isnew=1 ";
//			String ordersql = " order by id desc ";
//			String limitsql = " limit ";
//			String where = getWhere(data);
//			if(!where.equals(""))
//			{
//				countsql += where;
//				sql      += where;
//			}
//			
//			
//			MbMusicGcxxDao gcxxdao = new MbMusicGcxxDao();
//			MbGyByflDao byflDao = new MbGyByflDao();
//			MbGyMjflDao gyMjflDao = new MbGyMjflDao();
//			MbGyHsflDao gyHsflDao = new MbGyHsflDao();
//			MbGyNdDao gyNdDao = new MbGyNdDao();
//			MbGyYyDao gyYyDao = new MbGyYyDao();
//			MbGyZqDao gyZqDao = new MbGyZqDao();
//			List<Record> countlist = gcxxdao.getBySql(countsql);
//			int total = countlist.get(0).getIntValue("count");//获得总记录数
//			PageUtil page = new PageUtil(pagenumber, pagesize, total);
//			limitsql += page.getStart()+","+pagesize;
//			List<Record> list = gcxxdao.getBySql(sql+ordersql+limitsql);
//			// 组装数据
//			if(list!=null&&list.size()>0){
//				for(Record r:list){
//					boolean bmbs = gcxxdao.getFlowingData(r.getStrValue(MbMusicGcxx.COLLECTIONCODE));
//					if(bmbs){
//						// 已经编目
//						r.add("bmbs", "1");
//					}else{
//						// 未编目
//						r.add("bmbs", "0");
//					}
//					String year = r.getStrValue("year");
//					String class_bayin = r.getStrValue("class_bayin");
//					String class_minjian = r.getStrValue("class_minjian");
//					String class_huosa = r.getStrValue("class_huosa");
//					String language = r.getStrValue("language");
//					String usenation = r.getStrValue("usenation");
//					if(StringUtils.isNoEmpty(class_bayin)){
//						Record byId = byflDao.getById(Integer.parseInt(class_bayin));
//						class_bayin = byId.getStrValue("name");
//					}
//					if(StringUtils.isNoEmpty(class_minjian)){
//						Record byId = gyMjflDao.getById(Integer.parseInt(class_minjian));
//						class_minjian = byId.getStrValue("name");
//					}
//					if(StringUtils.isNoEmpty(class_huosa)){
//						Record byId = gyHsflDao.getById(Integer.parseInt(class_huosa));
//						class_huosa = byId.getStrValue("name");
//					}
//					if(StringUtils.isNoEmpty(year)){
//						Record byId1 = gyNdDao.getById(Integer.parseInt(year));
//						year = byId1.getStrValue("dynasty");
//					}
//					if(StringUtils.isNoEmpty(language)){
//						Record byId2 = gyYyDao.getById(Integer.parseInt(language));
//						language = byId2.getStrValue("name");
//					}
//					if(StringUtils.isNoEmpty(usenation)){
//						Record byId3 = gyZqDao.getById(Integer.parseInt(usenation));
//						usenation = byId3.getStrValue("name");
//					}
//					r.add("year", year);
//					r.add("class_bayin", class_bayin);
//					r.add("class_minjian", class_minjian);
//					r.add("class_huosa", class_huosa);
//					r.add("language", language);
//					r.add("usenation", usenation);
//				}
//			}
//			
//			record.add(Status.ROWS, list);
//			record.add(Status.TOTAL, total);
//			record.add(Status.PAGENUMBER, pagenumber);
//			record.add(Status.PAGESIZE, pagesize);
//			record.add(Status.PAGETOTAL, page.getPagetotal());
//		} catch (Exception e) {
//		  e.printStackTrace();
//			record.add(Status.SATUS, Status.FAILED);
//			record.add(Status.MSG, "数据异常！");
//		}
//		return record;
//	}

	/**
	 * 雷俊峰
	 * @param request
	 * @param response
	 * @param data
	 * @return
	 */
	public Record getJsData(HttpServletRequest request, HttpServletResponse response, Record data){
		Record record = new Record();
		
		try {
			
			MbGyYqflDao dao = new MbGyYqflDao();
			List<Record> all = dao.getAll();
			record.add("data", all);
			record.add(Status.SATUS, Status.OK);
		} catch (Exception e) {
			record.add(Status.SATUS, Status.FAILED);
			record.add(Status.MSG, "数据异常！");
		}
		return record;
	}

	
	/**
	 * 雷俊峰
	 * @param request
	 * @param response
	 * @param data
	 * @return
	 */
	public Record getMusicList(HttpServletRequest request, HttpServletResponse response, Record data){
		Record record = new Record();
		record.add(Status.SATUS, Status.OK);
		try {
			int pagenumber = data.getIntValue(Status.PAGENUMBER);// 获取当前页
			int pagesize = data.getIntValue(Status.PAGESIZE);// 获取每页多少条数据
			String countsql = "select count(*) as count from mb_music_sjjs where 1=1 ";
			String sql=" select * from mb_music_sjjs where 1=1 ";
			String ordersql = " order by id desc ";
			String limitsql = " limit ";
			

			String where = getWhere(data);
			if(!where.equals(""))
			{
				countsql += where;
				sql      += where;
			}
			
			MbsjjsDao sjjsDao= new MbsjjsDao();
			
			List<Record> countlist = sjjsDao.getBySql(countsql);
			int total = countlist.get(0).getIntValue("count");//获得总记录数
			PageUtil page = new PageUtil(pagenumber, pagesize, total);
			limitsql += page.getStart()+","+pagesize;
			
			List<Record> list = sjjsDao.getBySql(sql+ordersql+limitsql);
			
			// 组装数据
			record.add(Status.ROWS, list);
			record.add(Status.TOTAL, total);
			record.add(Status.PAGENUMBER, pagenumber);
			record.add(Status.PAGESIZE, pagesize);
			record.add(Status.PAGETOTAL, page.getPagetotal());
		} catch (Exception e) {
			record.add(Status.SATUS, Status.FAILED);
			record.add(Status.MSG, "数据异常！");
		}
		return record;
	}
	
	
	
	
	/**
	 * 雷俊峰
	 * @param request
	 * @param response
	 * @param data
	 * @return
	 */
	public Record getDetailById(HttpServletRequest request, HttpServletResponse response, Record data){
	  String[] tables = {MbMusicXzxx.MB_MUSIC_XZXX_TABLE_NAME,
          MbMusicWhrlxxx.MB_MUSIC_WHRLXXX_TABLE_NAME,
          MbMusicYxxx.MB_MUSIC_YXXX_TABLE_NAME,};
      Record record = new Record();
      try {
        int gcxxid = data.getIntValue("id");
        MbMusicGcxxDao dao = new MbMusicGcxxDao();
        Record gcxx = dao.getById(gcxxid);
        if (gcxx == null) throw new Exception("查询不到馆藏信息！");
        for (String table : tables) {
          String sql = "select * from " + table + " where gcxxid=" + gcxxid;
          List<Record> list = dao.getBySql(sql);
          if (!list.isEmpty()) {
            Record r = list.get(0);
            for (String fld : r.getAllFlds()) {
              gcxx.add(fld, r.getValue(fld));
            }
          }
        }      


        String[] imagesByZdbh = new String[]{"formDrawing", "improveStateImage","mediatorMaterialImage"
            ,"vibrationTransferMaterialImage", "vibrationTransferStructImage","spectrumAnalysisImage",
            "resonatorMaterialImage","resonatorStrutImage","spectrumImage","spectrumAnalysisImage",
            "mediatorStructImage","vibrationTransferStructImage","structImage",
            "resonatorMaterialImage","resonatorStrutImage","spectrumImage","spectrumAnalysisImage"
            ,"mediatorStructImage","originImage","musicScoreImage","historyImage","folkloreImage","faithImage"};
        String[] audioByZdbh = new String[]{"pitchAudio", "toneAudio", "temperamentAudio", 
            "bestRegisterAudio", "toneMethodAudio", "mainPartSoundAudio","rangeAudio","mediatorShapeAudio",
            "mainPartSoundAudio","faithAudio","historyAudio","originAudio","folkloreAudio"};
        String[] videoByZdbh = new String[]{"voiceMechanismVideo", "provokeVideo","structVideo",
            "techniquesVideo","inheritTeachVideo","techniquesVideo","inheritTeachVideo","faithVideo",
            "originVideo","folkloreVideo","historyVideo"};
        String[] ThreedimensionalmodelByZdbh = new String[]{};
        String[] LiteratureByZdbh = new String[]{};
        
        MbManageImageDao imagedao = new MbManageImageDao();
        for (String resource : imagesByZdbh) {
          List<Record> ls = imagedao.getBySql("select * from "+MbManageImage.MB_MANAGE_IMAGE_TABLE_NAME
              +" where zdbh='" + gcxx.getStrValue(resource) + "'");
          if (!ls.isEmpty()) {
            gcxx.add(resource + "1", ls.get(0).getStrValue("title"));
          }
        }
        MbManageAudiofrequencyDao audiodao = new MbManageAudiofrequencyDao();
        for (String resource : audioByZdbh) {
          List<Record> ls = audiodao.getBySql("select * from "
                                              +MbManageAudiofrequency.MB_MANAGE_AUDIOFREQUENCY_TABLE_NAME
              +" where zdbh='" + gcxx.getStrValue(resource) + "'");
          if (!ls.isEmpty()) {
            gcxx.add(resource + "1", ls.get(0).getStrValue("title"));
          }
        }
        MbManageVideoDao videodao = new MbManageVideoDao();
        for (String resource : videoByZdbh) {
          List<Record> ls = videodao.getBySql("select * from "+MbManageVideo.MB_MANAGE_VIDEO_TABLE_NAME
              +" where zdbh='" 
        + gcxx.getStrValue(resource) + "'");
          if (!ls.isEmpty()) {
            gcxx.add(resource + "1", ls.get(0).getStrValue("title"));
          }
        }
        MbManageThreedimensionalmodelDao tdmdao = new MbManageThreedimensionalmodelDao();
        for (String resource : ThreedimensionalmodelByZdbh) {
          List<Record> ls = tdmdao.getBySql("select * from "
        +MbManageThreedimensionalmodel.MB_MANAGE_THREEDIMENSIONALMODEL_TABLE_NAME
        +" where zdbh='" + gcxx.getStrValue(resource) + "'");
          if (!ls.isEmpty()) {
            gcxx.add(resource + "1", ls.get(0).getStrValue("title"));
          }
        }
        MbManageLiteratureDao literaturedao = new MbManageLiteratureDao();
        for (String resource : LiteratureByZdbh) {
          List<Record> ls = literaturedao.getBySql("select * from "
              +MbManageLiterature.MB_MANAGE_LITERATURE_TABLE_NAME
              +" where zdbh='" + gcxx.getStrValue(resource) + "'");
          if (!ls.isEmpty()) {
            gcxx.add(resource + "1", ls.get(0).getStrValue("title"));
          }
        }
        
        
        
        String[] baseTables = {MbGyHsfl.MB_GY_HSFL_TABLE_NAME,MbGyMjfl.MB_GY_MJFL_TABLE_NAME};
        String[] fields = {"class_huosa","class_minjian"};
        MbXtglBaseTableServlet baseTableServlet = new MbXtglBaseTableServlet();
        for(int i=0;i<fields.length;i++){
          String f=fields[i];
          String value = gcxx.getStrValue(f);
          String text = "";
          if(StringUtils.isNoEmpty(value)){
            text = baseTableServlet.getNameById(baseTables[i],Integer.valueOf(value));
          }
          gcxx.add(f+"_text", text);
        }
        record.add(Status.SATUS, Status.OK);
        record.add(Status.DATA, gcxx);
      } catch (Exception e) {
        record.add(Status.SATUS, Status.FAILED);
        record.add(Status.MSG, "数据异常！");
      }
      return record;
	}
	
	public Record getDetailById_bak(HttpServletRequest request, HttpServletResponse response, Record data){
      Record record = new Record();
      try {
          HashMap<String, Object> hash = new HashMap<>();
          hash.put("id", data.getIntValue("id"));
          MbSjjsInfoDao infodao = new MbSjjsInfoDao();
          List<Record> listByProperty = infodao.getListByProperty(hash);
          Record datas = listByProperty.get(0);
          // 组装数据
          record.add("data", datas);
          record.add(Status.SATUS, Status.OK);
      } catch (Exception e) {
          record.add(Status.SATUS, Status.FAILED);
          record.add(Status.MSG, "数据异常！");
      }
      return record;
  }
/*	*//**
	 * 雷俊峰
	 * @param request
	 * @param response
	 * @param data
	 * @return
	 *//*
	@SuppressWarnings("unused")
	public Record getGCInfo(HttpServletRequest request, HttpServletResponse response, Record data){
		Record record = new Record();
		try {
			//影响Dao
			MbManageImageDao imageDao = new MbManageImageDao();
			//音频Dao
			MbManageAudiofrequencyDao audioDao = new MbManageAudiofrequencyDao();
			//视频Dao
			MbManageVideoDao videoDao = new MbManageVideoDao();
			

			
			Integer zdbh = data.getIntValue("zdbh");
			if(zdbh==null){
				record.add(Status.SATUS, Status.FAILED);
				record.add(Status.MSG, "数据异常！");
				return record;
			}
			//馆藏基本信息
			MbMusicGcxxDao gcDao = new MbMusicGcxxDao();
			Record gcxx = gcDao.getById(zdbh);
			record.add("gcxxData", gcxx);
			int gcxxId = gcxx.getIntValue(MbMusicGcxx.ZDBH);
			//形制信息
			MbMusicXzxxDao xzDao = new MbMusicXzxxDao();
			HashMap<String,Object> xzMap = new HashMap<String,Object>();
			xzMap.put("gcxxid", gcxxId);
			List<Record> xzxxList = xzDao.getListByProperty(xzMap);
			Record record2 = xzxxList.get(0);
			int formDrawing = record2.getIntValue(MbMusicXzxx.FORMDRAWING);			
			int formDescription = record2.getIntValue(MbMusicXzxx.FORMDESCRIPTION);			
			int improveStateImage = record2.getIntValue(MbMusicXzxx.IMPROVESTATEIMAGE);			
			
			Record formDrawings = imageDao.getById(formDrawing);
			Record improveStateImages = imageDao.getById(improveStateImage);
			Record formDescriptions = imageDao.getById(formDescription);
			
			record2.add(MbMusicXzxx.FORMDRAWING, formDrawings.getStrValue(MbManageImage.FILEID));
			record2.add(MbMusicXzxx.IMPROVESTATEIMAGE, improveStateImages.getStrValue(MbManageImage.FILEID));
			record2.add(MbMusicXzxx.FORMDESCRIPTION,formDescriptions.getStrValue(MbManageVideo.FILEID));
			record.add("xzxxData", record2);
			
			
			
			//影像隐隐
			MbMusicYxxxDao yxDao = new MbMusicYxxxDao();
			List<Record> yxxxList = yxDao.getListByProperty(xzMap);
			Record record3 = yxxxList.get(0);
			int pitchAudio = record3.getIntValue(MbMusicYxxx.PITCHAUDIO);
			int toneAudio = record3.getIntValue(MbMusicYxxx.TONEAUDIO);
			int rangeAudio = record3.getIntValue(MbMusicYxxx.RANGEAUDIO);
			int bestRegisterAudio = record3.getIntValue(MbMusicYxxx.BESTREGISTERAUDIO);
			int provokeVideo = record3.getIntValue(MbMusicYxxx.PROVOKEVIDEO);
			int structImage = record3.getIntValue(MbMusicYxxx.STRUCTIMAGE);
			int structVideo = record3.getIntValue(MbMusicYxxx.STRUCTVIDEO);
			int mediatorMaterialImage = record3.getIntValue(MbMusicYxxx.MEDIATORMATERIALIMAGE);
			int mediatorStructImage = record3.getIntValue(MbMusicYxxx.MEDIATORSTRUCTIMAGE);
			int mediatorShapeAudio = record3.getIntValue(MbMusicYxxx.MEDIATORSHAPEAUDIO);
			int VibrationTransferMaterialImage = record3.getIntValue(MbMusicYxxx.VIBRATIONTRANSFERMATERIALIMAGE);
			int VibrationTransferStructImage = record3.getIntValue(MbMusicYxxx.VIBRATIONTRANSFERSTRUCTIMAGE);
			int ResonatorMaterialImage = record3.getIntValue(MbMusicYxxx.RESONATORMATERIALIMAGE);
			int ResonatorStrutImage = record3.getIntValue(MbMusicYxxx.RESONATORSTRUTIMAGE);
			int MainPartSoundAudio = record3.getIntValue(MbMusicYxxx.MAINPARTSOUNDAUDIO);
			int techniquesVideo = record3.getIntValue(MbMusicYxxx.TECHNIQUESVIDEO);
			int spectrumImage = record3.getIntValue(MbMusicYxxx.SPECTRUMIMAGE);
			int SpectrumAnalysisImage = record3.getIntValue(MbMusicYxxx.SPECTRUMANALYSISIMAGE);
			int temperamentAudio = record3.getIntValue(MbMusicYxxx.TEMPERAMENTAUDIO);
			int toneMethodAudio = record3.getIntValue(MbMusicYxxx.TONEMETHODAUDIO);
			int voiceMechanismVideo = record3.getIntValue(MbMusicYxxx.VOICEMECHANISMVIDEO);
			
			
			Record voiceMechanismVideos = videoDao.getById(voiceMechanismVideo);
			Record toneMethodAudios = videoDao.getById(toneMethodAudio);
			Record temperamentAudios = audioDao.getById(temperamentAudio);
			Record pitchAudios = audioDao.getById(pitchAudio);
			Record toneAudios = audioDao.getById(toneAudio);
			Record rangeAudios = audioDao.getById(rangeAudio);
			Record bestRegisterAudios = audioDao.getById(bestRegisterAudio);
			Record provokeVideos = videoDao.getById(provokeVideo);
			Record structImages = imageDao.getById(structImage);
			Record structVideos = videoDao.getById(structVideo);
			Record mediatorMaterialImages = imageDao.getById(mediatorMaterialImage);
			Record mediatorStructImages = imageDao.getById(mediatorStructImage);
			Record mediatorShapeAudios = audioDao.getById(mediatorShapeAudio);
			Record VibrationTransferMaterialImages = imageDao.getById(VibrationTransferMaterialImage);
			Record VibrationTransferStructImages = imageDao.getById(VibrationTransferStructImage);
			Record ResonatorMaterialImages = imageDao.getById(ResonatorMaterialImage);
			Record ResonatorStrutImages = imageDao.getById(ResonatorStrutImage);
			Record MainPartSoundAudios = audioDao.getById(MainPartSoundAudio);
			Record techniquesVideos = videoDao.getById(techniquesVideo);
			Record spectrumImages = imageDao.getById(spectrumImage);
			Record SpectrumAnalysisImages = imageDao.getById(SpectrumAnalysisImage);
			
			
			record3.add(MbMusicYxxx.VOICEMECHANISMVIDEO, voiceMechanismVideos.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.TONEMETHODAUDIO, toneMethodAudios.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.TEMPERAMENTAUDIO, temperamentAudios.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.PITCHAUDIO, pitchAudios.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.TONEAUDIO, toneAudios.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.RANGEAUDIO, rangeAudios.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.BESTREGISTERAUDIO, bestRegisterAudios.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.PROVOKEVIDEO, provokeVideos.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.STRUCTIMAGE, structImages.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.STRUCTVIDEO, structVideos.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.MEDIATORMATERIALIMAGE, mediatorMaterialImages.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.MEDIATORSTRUCTIMAGE, mediatorStructImages.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.MEDIATORSHAPEAUDIO, mediatorShapeAudios.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.VIBRATIONTRANSFERMATERIALIMAGE, VibrationTransferMaterialImages.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.VIBRATIONTRANSFERSTRUCTIMAGE, VibrationTransferStructImages.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.RESONATORMATERIALIMAGE, ResonatorMaterialImages.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.RESONATORSTRUTIMAGE, ResonatorStrutImages.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.MAINPARTSOUNDAUDIO, MainPartSoundAudios.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.TECHNIQUESVIDEO, techniquesVideos.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.SPECTRUMIMAGE, spectrumImages.getStrValue(MbManageImage.FILEID));
			record3.add(MbMusicYxxx.SPECTRUMANALYSISIMAGE, SpectrumAnalysisImages.getStrValue(MbManageImage.FILEID));
			record.add("yxxxData", record3);
			//文化人 人文信息
			MbMusicWhrlxxxDao whrDao = new MbMusicWhrlxxxDao();
			List<Record> whrList = whrDao.getListByProperty(xzMap);
			Record wherRecord = whrList.get(0);
			
			int originImage = wherRecord.getIntValue(MbMusicWhrlxxx.ORIGINIMAGE);
			int originAudio = wherRecord.getIntValue(MbMusicWhrlxxx.ORIGINAUDIO);
			int originVideo = wherRecord.getIntValue(MbMusicWhrlxxx.ORIGINVIDEO);
			int historyImage = wherRecord.getIntValue(MbMusicWhrlxxx.HISTORYIMAGE);
			int historyAudio = wherRecord.getIntValue(MbMusicWhrlxxx.HISTORYAUDIO);
			int historyVideo = wherRecord.getIntValue(MbMusicWhrlxxx.HISTORYVIDEO);
			int folkloreImage = wherRecord.getIntValue(MbMusicWhrlxxx.FOLKLOREIMAGE);
			int folkloreAudio = wherRecord.getIntValue(MbMusicWhrlxxx.FOLKLOREAUDIO);
			int folkloreVideo = wherRecord.getIntValue(MbMusicWhrlxxx.FOLKLOREVIDEO);
			int faithImage = wherRecord.getIntValue(MbMusicWhrlxxx.FAITHIMAGE);
			int faithAudio = wherRecord.getIntValue(MbMusicWhrlxxx.FAITHAUDIO);
			int faithVideo = wherRecord.getIntValue(MbMusicWhrlxxx.FAITHVIDEO);
			
			
			Record originImages = imageDao.getById(originImage);
			Record originAudios = audioDao.getById(originAudio);
			Record originVideos = videoDao.getById(originVideo);
			Record historyImages = imageDao.getById(historyImage);
			Record historyAudios = audioDao.getById(historyAudio);
			Record historyVideos = videoDao.getById(historyVideo);
			Record folkloreImages = imageDao.getById(folkloreImage);
			Record folkloreAudios = audioDao.getById(folkloreAudio);
			Record folkloreVideos = videoDao.getById(folkloreVideo);
			Record faithImages = imageDao.getById(faithImage);
			Record faithAudios = audioDao.getById(faithAudio);
			Record faithVideos = videoDao.getById(faithVideo);
			
			wherRecord.add(MbMusicWhrlxxx.ORIGINIMAGE, originImages.getStrValue(MbManageImage.FILEID));
			wherRecord.add(MbMusicWhrlxxx.ORIGINAUDIO, originAudios.getStrValue(MbManageImage.FILEID));
			wherRecord.add(MbMusicWhrlxxx.ORIGINVIDEO, originVideos.getStrValue(MbManageImage.FILEID));
			wherRecord.add(MbMusicWhrlxxx.HISTORYIMAGE, historyImages.getStrValue(MbManageImage.FILEID));
			wherRecord.add(MbMusicWhrlxxx.HISTORYAUDIO, historyAudios.getStrValue(MbManageImage.FILEID));
			wherRecord.add(MbMusicWhrlxxx.HISTORYVIDEO, historyVideos.getStrValue(MbManageImage.FILEID));
			wherRecord.add(MbMusicWhrlxxx.FOLKLOREIMAGE, folkloreImages.getStrValue(MbManageImage.FILEID));
			wherRecord.add(MbMusicWhrlxxx.FOLKLOREAUDIO, folkloreAudios.getStrValue(MbManageImage.FILEID));
			wherRecord.add(MbMusicWhrlxxx.FOLKLOREVIDEO, folkloreVideos.getStrValue(MbManageImage.FILEID));
			wherRecord.add(MbMusicWhrlxxx.FAITHIMAGE, faithImages.getStrValue(MbManageImage.FILEID));
			wherRecord.add(MbMusicWhrlxxx.FAITHAUDIO, faithAudios.getStrValue(MbManageImage.FILEID));
			wherRecord.add(MbMusicWhrlxxx.FAITHVIDEO, faithVideos.getStrValue(MbManageImage.FILEID));
			
			record.add("whrlxxData", wherRecord);
			//获取人文ID
			int whrZdbh = wherRecord.getIntValue(MbMusicWhrlxxx.ZDBH);
			//获取文化事项信息
			MbMusicWhsxWhrlxDao whsxwhrDao = new MbMusicWhsxWhrlxDao();
			HashMap<String,Object> Map = new HashMap<String,Object>();
			Map.put("whrlxid", whrZdbh);
			List<Record> whsxwhrList = whsxwhrDao.getListByProperty(Map);
			Record whsxwhrEntity = whsxwhrList.get(0);
			int whsxId = whsxwhrEntity.getIntValue(MbMusicWhsxWhrlx.WHSXID);
			MbMusicWhsxDao whsxDao = new MbMusicWhsxDao();
			Record whsxDate = whsxDao.getById(whsxId);
			
			int musicScoreImage = whsxDate.getIntValue(MbMusicWhsx.MUSICSCOREIMAGE);
			int inheritTeachVideo = whsxDate.getIntValue(MbMusicWhsx.INHERITTEACHVIDEO);
			
			Record musicScoreImages = imageDao.getById(musicScoreImage);
			Record inheritTeachVideos = videoDao.getById(inheritTeachVideo);
			
			
			whsxDate.add(MbMusicWhsx.MUSICSCOREIMAGE, musicScoreImages.getStrValue(MbManageImage.FILEID));
			whsxDate.add(MbMusicWhsx.INHERITTEACHVIDEO, inheritTeachVideos.getStrValue(MbManageImage.FILEID));
			
			record.add("whxxData", whsxDate);
			//获取代表文物信息
			MbMusicDbrwWhrlxDao dbwhDao = new MbMusicDbrwWhrlxDao();
			List<Record> dbwhList = dbwhDao.getListByProperty(Map);
			Record dbwhData = dbwhList.get(0);
			int dbrwId = dbwhData.getIntValue(MbMusicDbrwWhrlx.ZDBH);
			MbMusicDbrwDao dbDao = new MbMusicDbrwDao();
			Record dbwwData = dbDao.getById(dbrwId);
			record.add("dbwwData", dbwwData);
			
			record.add(Status.SATUS, Status.OK);
		} catch (Exception e) {
			record.add(Status.SATUS, Status.FAILED);
			record.add(Status.MSG, "数据异常！");
		}
		return record;
	}
	*/
	@rquestMethod(MethodNote = ReqMode.All)
	@TransAnnotation(isTrans=true)
	public Record insert(HttpServletRequest request, HttpServletResponse response, Record data) {
		Record result = new Record();
	try {	
		MbMusicGcxxDao gcDao = new MbMusicGcxxDao();	
		
		String collection_code = data.getStrValue(MbMusicGcxx.COLLECTIONCODE);
		Record res = new Record();
		res.add("collection_code", collection_code);
		List<Record> list = gcDao.getListByProperty(res);
		if(list!=null && list.size()>0) {
			throw new Exception("数据已经存在！");
		}else {
			int isnew = 1;
			int isrunning=1;
			data.add("isnew", isnew);
			data.add("isrunning", isrunning);
			 if(gcDao.insert(data)) {
				  result.add(Status.SATUS,Status.OK);
			  }else {
				  throw new Exception("分配专家信息失败！");  
			  }
		}
	}catch (Exception e) {
        logger.error(e.getMessage());
        e.printStackTrace();
        // 事务回滚，事务模式下，此标识将使此次事务回滚
        result.add(Status.SATUS, Status.FAILED);
    }
    return result;
	}

	public String getWhere(Record data){
		String where = "";
		// 查询条件,藏品号
		String collection_code = data.getStrValue("collection_code");
		if(StringUtils.isNoEmpty(collection_code)){
			where += " and collection_code like '%"+collection_code+"%%' ";
		}
		// 查询条件,根据名称模糊查询
		String title = data.getStrValue("yqmc");
		if(StringUtils.isNoEmpty(title)){
			where += " and title like '%"+title+"%' ";
		}
		
		// 查询条件,根据八音分类查询
		String class_bayin1 = data.getStrValue("class_bayin");
		if(StringUtils.isNoEmpty(class_bayin1)){
			where += " and class_bayin ="+class_bayin1;
		}
					
		// 查询条件,根据民间分类
		String class_minjian_ = data.getStrValue("class_minjian");
		String class_minjian_showchild = data.getStrValue("class_minjian_showchild");
		if(StringUtils.isNoEmpty(class_minjian_showchild)){
			MbXtglBaseTableServlet servlet = new MbXtglBaseTableServlet();
			if(StringUtils.isNoEmpty(class_minjian_)){
				class_minjian_ = servlet.getAllChildrenId4Select(Integer.valueOf(class_minjian_), "mb_gy_mjfl");
				where += " and class_minjian in ("+class_minjian_+")";
			}
		}else{
			if(StringUtils.isNoEmpty(class_minjian_)){
				where += " and class_minjian ="+class_minjian_;
			}
		}
		
		
		String class_huosa_ = data.getStrValue("class_huosa");
		String class_huosa_showchild = data.getStrValue("class_huosa_showchild");
		if(StringUtils.isNoEmpty(class_huosa_showchild)){
			MbXtglBaseTableServlet servlet = new MbXtglBaseTableServlet();
			if(StringUtils.isNoEmpty(class_huosa_)){
				class_huosa_ = servlet.getAllChildrenId4Select(Integer.valueOf(class_huosa_), "mb_gy_hsfl");
				where += " and class_huosa in ("+class_huosa_+")";
			}
		}else{
			if(StringUtils.isNoEmpty(class_huosa_)){
				where += " and class_huosa ="+class_huosa_;
			}
		}
		
		// 查询条件,根据年代查询
		String year1 = data.getStrValue("year");
		if(StringUtils.isNoEmpty(year1)){
			where += " and year like '%"+year1+"%' ";
		}
		
		// 查询条件,根据出土地点查询
		String unearthedplace = data.getStrValue("unearthedplace");
		if(StringUtils.isNoEmpty(unearthedplace)){
			where += " and unearthedplace like '%"+unearthedplace+"%' ";
		}
		
		// 查询条件,根据采集地点查询
		String collectionPlace = data.getStrValue("collectionPlace");
		if(StringUtils.isNoEmpty(collectionPlace)){
			where += " and collectionPlace like '%"+collectionPlace+"%' ";
		}
		
		// 查询条件,根据自称模糊查询
		String title_self = data.getStrValue("title_self");
		if(StringUtils.isNoEmpty(title_self)){
			where += " and title_self like '%"+title_self+"%' ";
		}
		
		// 查询条件,根据关键字模糊查询
		String gjz = data.getStrValue("gjz");
		if(StringUtils.isNoEmpty(gjz)){
			where += " and gjz like '%"+gjz+"%' ";
		}
		return where;			
	}
	public String getwhere2(Record data){
		String where = "";
		// 查询条件,藏品号
		String collection_code = data.getStrValue("collection_code");
		if(StringUtils.isNoEmpty(collection_code)){
			where += " and collection_code like '%"+collection_code+"%' ";
		}
		
		// 查询条件,根据名称模糊查询
		String title = data.getStrValue("yqmc");
		if(StringUtils.isNoEmpty(title)){
			where += " and title like '%"+title+"%' ";
		}
		
		// 查询条件,根据八音分类
		String class_bayin = data.getStrValue("class_bayin");
		if(StringUtils.isNoEmpty(class_bayin)){
			where += " and class_bayin ="+class_bayin;
		}
		
		// 查询条件,根据民间分类
		String class_minjian = data.getStrValue("class_minjian");
		String class_minjian_showchild = data.getStrValue("class_minjian_showchild");
		if(StringUtils.isNoEmpty(class_minjian_showchild)){
			MbXtglBaseTableServlet servlet = new MbXtglBaseTableServlet();
			if(StringUtils.isNoEmpty(class_minjian)){
				class_minjian = servlet.getAllChildrenId4Select(Integer.valueOf(class_minjian), "mb_gy_mjfl");
				where += " and class_minjian in ("+class_minjian+")";
			}
		}else{
			if(StringUtils.isNoEmpty(class_minjian)){
				where += " and class_minjian ="+class_minjian;
			}
		}
		
		// 查询条件,根据霍萨分类
		String class_huosa = data.getStrValue("class_huosa");
		String class_huosa_showchild = data.getStrValue("class_huosa_showchild");
		if(StringUtils.isNoEmpty(class_huosa_showchild)){
			MbXtglBaseTableServlet servlet = new MbXtglBaseTableServlet();
			if(StringUtils.isNoEmpty(class_huosa)){
				class_huosa = servlet.getAllChildrenId4Select(Integer.valueOf(class_huosa), "mb_gy_hsfl");
				where += " and class_huosa in ("+class_huosa+")";
			}
		}else{
			if(StringUtils.isNoEmpty(class_huosa)){
				where += " and class_huosa ="+class_huosa;
			}
		}
		return where;
	}
	
}
